import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
    {
      path: '/login',
      component: () => import('@/views/login/index'),
      hidden: true
    },
    {
      path: '/404',
      component: () => import('@/views/error-page/404'),
      hidden: true
    },
    {
      path: '/401',
      component: () => import('@/views/error-page/401'),
      hidden: true
    }
  ]

// re
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/test-index',
    alwaysShow: true,
    meta: { title: '测试首页', icon: 'daoru' },
    children: [
      {
        path: 'test-index',
        component: () => import('@/views/test-index/TestIndex.vue'),
        name: 'TestIndex',
        meta: { title: '测试首页', icon: 'v_monitor' }
      },
      // {
      //   path: 'test-index2',
      //   component: () => import('@/views/test-index/TestIndex.vue'),
      //   name: 'TestIndex2',
      //   meta: { title: '富文本编辑器', icon: 'v_monitor' }
      // },
      // {
      //   path: 'keep-alive-test',
      //   component: () => import('@/views/test-index/KeepAliveTest.vue'),
      //   name: 'KeepAliveTest',
      //   meta: { title: 'keepAlive测试', icon: 'v_monitor', activeMenu: '/test-index' },
      //   hidden: true
      // }
    ]
  },
  {
    path: '/element-demo',
    component: Layout,
    alwaysShow: false,
    meta: { title: 'element-demo', icon: 'tree-table' },
    children: [
      {
        path: 'element-demo',
        component: () => import('@/views/element-demo'),
        name: 'ElementDemo',
        meta: { title: 'element-demo', icon: 'v_monitor', affix: false, noCache: false }
      },
      // {
      //   path: 'device-info-manage',
      //   component: () => import('@/views/device-info-manage/DeviceInfoManage.vue'),
      //   name: 'DeviceInfoManage',
      //   meta: { title: '真实的用例', icon: 'v_monitor', affix: false, noCache: false }
      // },
      {
        path: 'multi-throd',
        component: () => import('@/views/element-demo/MultiThrod.vue'),
        name: 'MultiThrod',
        meta: { title: 'js多线程', icon: 'v_monitor', affix: false, noCache: false }
      }
    ]
  },
  /* 如果需要iView则引入*/
  // {
  //   path: '/iview-demo',
  //   component: Layout,
  //   alwaysShow: false,
  //   meta: { title: 'IviewDemo', icon: 'tree-table' },
  //   children: [
  //     {
  //       path: 'iview-demo',
  //       component: () => import('@/views/iview-demo/IviewDemo.vue'),
  //       name: 'IviewDemo',
  //       meta: { title: 'IviewDemo', icon: 'v_monitor', affix: true, noCache: false }
  //     }
  //   ]
  // },
  /* 以下是配置案例*/
  // {
  //   path: '/wkt-manage',
  //   component: Layout,
  //   redirect: '/wkt-manage/article-manage',
  //   alwaysShow: true,
  //   name: '用车微课堂',
  //   meta: { title: '用车微课堂', icon: 'micro_courses' },
  //   children: [
  //     {
  //       path: 'article-manage',
  //       component: () => import('@/views/wkt-manage/article-manage'),
  //       name: 'WktArticleManage',
  //       meta: { title: '文章管理' }
  //     },
  //     {
  //       path: 'cat-detail',
  //       component: () => import('@/views/wkt-statistic/cart-team-statistics/CartDetail'),
  //       name: 'CartDetail',
  //       meta: { title: '车辆详情',activeMenu:"/cart-team-statistics/CartDetail"},
  //       hidden: true
  //     }
  //   ]
  // },
  // {
  //   path: '/experiment-center-new',
  //   component: Layout,
  //   redirect: '/experiment-center-new/config-management',
  //   alwaysShow: true,
  //   name: 'ExperimentCenter',
  //   meta: { title: '按需采集-new', icon: 'vds'},
  //   children: [
  //     {
  //       path: 'config-management',
  //       component: () => import('@/views/experiment-center-new/config-management'),
  //       name: '配置管理',
  //       meta: { title: '配置管理'}
  //     },
  //     {
  //       path: 'channel-management',
  //       component: () => import('@/views/experiment-center-new/channel-management'),
  //       name: 'ChannelManagement',
  //       meta: { title: '通道管理'}
  //     },
  //     {
  //       path: 'config-task-list',
  //       component: () => import('@/views/experiment-center-new/config-management/ConfigTaskList.vue'),
  //       name: 'ConfigTaskList',
  //       meta: { title: '任务管理'},
  //       hidden:true
  //     },
  //   ]
  // },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
